package com.stork.cms.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

import com.stork.cms.R;
import com.stork.cms.adapter.GridMenuAdapter;
import com.stork.cms.model.GridMenu;

public class GridHomeMenuActivity extends Activity {
    private GridView menuGridView;
    private Toast toast;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grid_home_menu);
		intializeView();
	}

	private void intializeView(){
		int menuName[] = { R.string.grid_menu_attendance,
				R.string.grid_menu_exam_schedule,
				R.string.grid_menu_exam_marks, R.string.grid_menu_lms,
				R.string.grid_menu_fees_details, R.string.grid_menu_calendar,
				R.string.grid_menu_profile, R.string.grid_menu_contact_us };

		int menuImageId[] = { R.drawable.resizeattance,
				R.drawable.resizeexamschedule, R.drawable.resizemarks,
				R.drawable.resizelms, R.drawable.resizefees,
				R.drawable.resizecalender, R.drawable.resizeprofile,
				R.drawable.resizecontactus };
		
		List<GridMenu> menuList = new ArrayList<GridMenu>();
		for(int i=0;i<menuName.length;i++){
			GridMenu gridMenu=new GridMenu(getString(menuName[i]), menuImageId[i]);
			menuList.add(gridMenu);
		}
		
		menuGridView=(GridView)findViewById(R.id.menurGidView);
		
		GridMenuAdapter gridMenuAdapter=new GridMenuAdapter(this, menuList);
		menuGridView.setAdapter(gridMenuAdapter);
		
		menuGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				if (position == 0) {
					Intent attendance=new Intent(GridHomeMenuActivity.this,AttendanceActivity.class);
					startActivity(attendance);
				} else if (position == 1) {
					displayToast(getString(R.string.future_under_development));
				} else if (position == 2) {
					Intent marklist=new Intent(GridHomeMenuActivity.this, MarkList.class);
					startActivity(marklist);
				} else if (position == 3) {
					displayToast(getString(R.string.future_under_development));
				} else if (position == 4) {
					Intent fees=new Intent(GridHomeMenuActivity.this,CollegeFeesActivity.class);
					startActivity(fees);
				} else if (position == 5) {
//					Intent calendarIntent=new Intent(GridHomeMenuActivity.this, Calendaractivity.class);
//					startActivity(calendarIntent);
				} else if (position == 6) {
//					displayToast(getString(R.string.future_under_development));
					Intent profile=new Intent(GridHomeMenuActivity.this,CollegeStudentProfile.class);
					startActivity(profile);
				} else if (position == 7) {
					Intent contactus=new Intent(GridHomeMenuActivity.this, Contactus.class);
					startActivity(contactus);
				}
				
			}
		});
		
	}

	
	private void displayToast(String msg){
		if(toast!=null){
			toast.cancel();
		}
		toast=Toast.makeText(this, msg,Toast.LENGTH_SHORT);
		toast.show();
	}
}
